<?php

define('DS', DIRECTORY_SEPARATOR);
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('NL', "\n");
define('TAB', "\t");

/**
 * @todo The following needs to be refactored, non-core classes should be on a per request basis
 */
require_once 'conf'.DS.'default'.EXT;
require_once 'lib'.DS.'singletonenforcer'.EXT;
require_once 'lib'.DS.'db'.EXT;
require_once 'lib'.DS.'mysql'.EXT;
require_once 'lib'.DS.'db_result'.EXT;
require_once 'lib'.DS.'configuration'.EXT;
require_once 'lib'.DS.'security'.EXT;
require_once 'lib'.DS.'controller'.EXT;
require_once 'lib'.DS.'viewbase'.EXT;
require_once 'lib'.DS.'viewhtml'.EXT;
require_once 'lib'.DS.'viewjson'.EXT;
require_once 'lib'.DS.'viewcsv'.EXT;
require_once 'lib'.DS.'filter'.EXT;
require_once 'lib'.DS.'version'.EXT;
require_once 'lib'.DS.'htmlhelper'.EXT;
require_once 'lib'.DS.'request'.EXT;
require_once 'lib'.DS.'collection'.EXT;
require_once 'lib'.DS.'listitemcollection'.EXT;
require_once 'lib'.DS.'listitem'.EXT;
require_once 'lib'.DS.'numberformat'.EXT;
$db = new MySQL(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PREFIX);
$db->connect();

//mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
//mysql_select_db(DB_DATABASE);

$config = new Configuration;
$security = new Security;

if(!$security->isAuthenticated()) {
	require_once 'app/login.php';
	$controller = new Login_Controller();
} else {
	// we are now logged in!
	$section	= isset($_REQUEST['section']) ? $_REQUEST['section'] : 'overview';
	$path	= 'app'.DS.$section.EXT;
	if(file_exists($path)) {
		require_once $path;
	} else {
		die('the requested section "'.$section.'" does not exist!');
	}
	$class = ucfirst($section).'_Controller';
	$controller = new $class;
}

$view	= $controller->GetView();

?>
